class Solution {
public:
    void mergerTreesHelper(TreeNode* t1, TreeNode* t2) {
        if (t1 == nullptr || t2 == nullptr) {
            return;
        }
        t1->val+=t2->val;
        if(t1->left==nullptr&&t2->left)
        {
            t1->left = t2->left;
        }
        else if(t1->left&&t2->left){
            mergerTreesHelper(t1->left,t2->left);
        }
        if(t1->right==nullptr&&t2->right)
        {
            t1->right = t2->right;
        }
        else if(t1->right&&t2->right){
            mergerTreesHelper(t1->right,t2->right);
        }
    }


    TreeNode* mergeTrees(TreeNode* t1, TreeNode* t2) {
        if (t1 == nullptr) {
            return t2; // 如果 t1 为空，直接返回 t2
        }
        if (t2 == nullptr) {
            return t1; // 如果 t2 为空，直接返回 t1
        }

        mergerTreesHelper(t1, t2); // 合并两棵树
        return t1;
    }
};